<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-dept-edit" th:object="${yhqType}">
			<input name="typeId" type="hidden" th:field="*{typeId}" />
			<input id="treeId" name="fId" type="hidden" th:field="*{fId}" />
			<div class="form-group">
				<label class="col-sm-3 control-label ">上级类型：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="treeName" onclick="selectTypeTree()" readonly="true" th:field="*{fName}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">类型名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="typeName" th:field="*{typeName}" id="typeName">
				</div>
			</div>
<!--			<div class="form-group">
				<label class="col-sm-3 control-label">类型级别：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="menu" th:field="*{menu}">
				</div>
			</div>-->

		</form>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript">
		var prefix = ctx + "gxgw_modules/yhqType";
		
		$("#form-dept-edit").validate({
			rules:{
				typeName:{
					required:true,
					remote: {
		                url: prefix + "/checkYhqTypeNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"typeId": function() {
		                        return $("#typeId").val();
		                    },
		                    "fId": function() {
		                        return $("input[name='fId']").val();
		                    },
		        			"typeName": function() {
		                        return $.common.trim($("#typeName").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
/*				menu:{
					required:true,
					digits:true
				},*/

			},
			messages: {
		        "typeName": {
		            remote: "类型已经存在"
		        }
		    }
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/edit", $('#form-dept-edit').serialize());
	        }
	    }
	
		/*类型管理-修改-选择类型树*/
		function selectTypeTree() {
			var typeId = $("#treeId").val();
			if(typeId > 0) {
			    var options = {
					title: '类型选择',
					width: "380",
					url: prefix + "/selectTypeTree/" + $("#treeId").val(),
					callBack: doSubmit
				};
				$.modal.openOptions(options);
			} else {
        		$.modal.alertError("父类型不能选择");
        	}
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowLastLevel(tree)) {
	   			var body = layer.getChildFrame('body', index);
	   			$("#treeId").val(body.find('#treeId').val());
	   			$("#treeName").val(body.find('#treeName').val());
	   			layer.close(index);
			}
		}
	</script>
</body>
</html>
